package org.msn.mapper.database;

import java.util.Map;

public abstract class CreateDatabaseLink<T> {
    private final String type;
    private final Map<String, Object> info;
    protected final DatabaseLinkPool<T> databaseLinkPool = new DatabaseLinkPool();

    protected CreateDatabaseLink(String type, Map<String, Object> info) {
        this.type = type;
        this.info = info;
        this.createDatabaseLink();
    }

    private void createDatabaseLink() {
        T obj = createDatabaseLink(info);
        databaseLinkPool.addLink(type, obj);
    }

    protected T getDatabaseLink() {
        return databaseLinkPool.getLink(type);
    }

    protected abstract T createDatabaseLink(Map<String, Object> info);
}
